#!/usr/bin/python3

'''
Created on Mar 8, 2016

@author: grind
'''
import sys
import urllib.request
import urllib.response
import urllib.error
import json
import time
import string
from bs4 import BeautifulSoup

def openCircle(circleId):
    request = urllib.request.urlopen("http://t.10jqka.com.cn/newcircle/live/getChatList/?fid=" + circleId + "&sort=up&pid=0&master=1")
    html = request.read()
    details = html.decode("utf8")
    #print(details)
    ojt = json.loads(details)
    return ojt.get("result")

def parseHtml(htmDoc):
        #print(html_doc)
    soup = BeautifulSoup(htmlDoc)
    chatContents = soup.find_all('div', 'chat-content')
    
    for chatContent in chatContents :
        print(chatContent.get_text().replace('\r\n','').replace('\n\n','').replace('  ',''))
        print("-" * 50)
        
if __name__ == '__main__':
    opt = 0;
    if len(sys.argv) > 1:
        opt = int(sys.argv[1])
    
    if opt == 1 :
        circleId = "8530";
    elif opt == 2:
        circleId = "12576"
    else:
        circleId = "8530";
    #http://t.10jqka.com.cn/circle/12576/
    htmlDoc  = openCircle(circleId)
    parseHtml(htmlDoc)

  